<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      align-items: center;
      margin-top: 30px;
      max-width: 1000px;
    }
    img {
      max-width: 100%;
    }
    .left {
      flex: 6;
    }
    .right {
      flex: 4;
      padding: 20px;
    }
    .color-box {
      width: 300px;
      height: 300px;
    }
  </style>
</head>
<body>


  <input type="file" />

  <div class="box">
    <div class="left">

    </div>
    <div class="right">
      <div class="color-box"></div>
    </div>
  </div>

  <script src="avg-color.js"></script>
  <script>

    function showImage(url) {
      document.querySelector('.left').innerHTML = `<img src="${url}">`
    }

    function showColor(color) {
      document.querySelector('.color-box').style.backgroundColor = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`
    }

    document.querySelector('input[type="file"]').addEventListener('change', function() {
      var url = URL.createObjectURL(this.files[0])
      showImage(url)

      getAvgColor(url, function(color) {
        console.log(color)
        showColor(color)
      })
    }, false)

  </script>
  
</body>
</html>
